using Ns.Threading;

namespace Ns.Data.Entity
{
    /// <summary>
    /// <para>Overrides the default <see cref="PersistChange"/> within a code block.</para>
    /// <para>
    /// This scope should be considered for setting the <see cref="IPersistEntity.PersistChange"/> of entity 
    /// to a value different from the default one (<see cref="PersistChange.Insert"/>).
    /// </para>
    /// </summary>
    /// <example>
    /// In the example below the <see cref="PersistChangeScope"/> sets 
    /// the <see cref="IPersistEntity.PersistChange"/> of each entity 
    /// instanciated within the scope to <see cref="PersistChange.Delete"/>.
    /// <code>
    /// void GetDeletedCompanies(DateTime establishedOn)
    /// {
    ///     using (new PersistChangeScope(PersistChange.Delete))
    ///     {
    ///         return GetCompanies(establishedOn);
    ///     }
    /// }
    /// </code>
    /// </example>
    public sealed class PersistChangeScope : Scope<PersistChange?>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PersistChangeScope"/> class.
        /// </summary>
        /// <param name="persistChange">The persist change.</param>
        public PersistChangeScope(PersistChange persistChange)
            : base(persistChange)
        {
        }

        /// <summary>
        /// Prevents a default instance of the <see cref="PersistChangeScope"/> class from being created.
        /// </summary>
        private PersistChangeScope()
        {
        }
    }
}